package org.example;

/**
 * <b>MyThread.java</b></br>
 *
 * <pre>使用继承Thread类创建子线程</pre>
 *
 * @author zhoulihao xiaogezhou929@163.com
 * @date 2021年06月05日 10:39:33
 * @since JDK 1.8
 */
public class MyThread extends  Thread {
        private String name;
        public MyThread(String name){
            this.name=name;
            System.out.println("创建线程"+name);
        }

        @Override
        public void run() {
            for (int i = 0; i < 3; i++) {
                //isAlive()判断当前线程是否处于运行状态
                System.out.println("线程的运行状态>>>>"+this.isAlive());
                System.out.println("运行线程 " + name + " " + i);
                // 线程休眠，增强线程交互执行的效果
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("\r\n退出线程 " + name);
        }
}
